#ifndef XMATERIAL_H
#define XMATERIAL_H
#include "Shader.h"
#include "Sampler.h"
#include <vector>
#include <map>

class Material
{
public:
	std::string name;
	VertexShader* vs;
	PixelShader* ps;
	unsigned char* uniformDataStoreVertex;
	unsigned char* uniformDataStorePixel;
	std::map<int, Texture*> textureList;
	//std::vector<MaterialUniformMap> uniformMapVertex;
	//std::vector<MaterialUniformMap> uniformMapPixel;
	//ID3D11Buffer* uniformBufferVertex;
	//ID3D11Buffer* uniformBufferPixel;
	bool needUpdateUniformBufferVertex;
	bool needUpdateUniformBufferPixel;
	std::vector<ID3D11ShaderResourceView*> shaderResourcePixel;
	std::map<int, Sampler*> samplerState;
	Material(const std::string name)
	{
		this->name.clear();
		this->name.append(name);
		std::string vsName = "";
		vsName.append(name);
		vsName.append("_VS.cso");
		uniformDataStoreVertex = NULL;
		uniformDataStorePixel = NULL;
		//uniformBufferVertex = NULL;
		//uniformBufferPixel = NULL;
		needUpdateUniformBufferVertex = true;
		needUpdateUniformBufferPixel = true;
		vs = ShaderManager::GetInstance()->LoadVertexShaderFromFile(vsName.c_str());
		if(vs->sizeOfShaderUniforms > 0)
		{
			uniformDataStoreVertex = new unsigned char[vs->sizeOfShaderUniforms];
		}
		std::string psName = "";
		psName.append(name);
		psName.append("_PS.cso");
		ps = ShaderManager::GetInstance()->LoadPixelShaderFromFile(psName.c_str());
		if(ps->sizeOfShaderUniforms)
		{
			uniformDataStorePixel = new unsigned char[ps->sizeOfShaderUniforms];
		}
	}
	~Material()
	{
		vs = NULL;
		ps = NULL;
		SafeDeleteArray(uniformDataStoreVertex);
		SafeDeleteArray(uniformDataStorePixel);
		//uniformBufferVertex->Release();
		//uniformBufferVertex = NULL;
		//uniformBufferPixel->Release();
		//uniformBufferPixel = NULL;
		needUpdateUniformBufferVertex = true;
		needUpdateUniformBufferPixel = true;
	}
	bool SetUniformVertexByType(UINT type, void* data);
	bool SetUniformPixelByType(UINT type, void* data);
	bool PushMaterialDataVertex();
	bool PushMaterialDataPixel();
private:
	bool UpdateUniformBufferVertex();
	bool UpdateUniformBufferPixel();
};
#endif